﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
#endif

public class RenderTextureFree : MonoBehaviour
{

	public static Texture Capture( Rect captureZone, int destX, int destY, string savenum )
	{
		Texture2D result;
		result = new Texture2D( Mathf.RoundToInt( captureZone.width ) + destX, Mathf.RoundToInt( captureZone.height ) + destY, TextureFormat.RGB24, false);
		result.ReadPixels(captureZone, destX, destY, false);
		result.Apply();
		byte[] bytez = result.EncodeToPNG();
		System.IO.File.WriteAllBytes(Application.dataPath + "/Textures/Save" + savenum  + ".png", bytez);
		return result;
	}
}